package com.javastudy.liuhouse.xml_json;

import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class Jackson {

    //使用JackSon解析XML，可以直接把XML解析为JavaBean，十分方便
    @Test
    public void testJackJson() throws IOException {
        InputStream input = getClass().getClassLoader().getResourceAsStream("demo.xml");
        //实例化JackSon模块
        JacksonXmlModule module = new JacksonXmlModule();
        //创建一个解析xml的模块对象
        XmlMapper mapper = new XmlMapper(module);
        //将xml文件读取,并且和Book对象里面的字段一一对应
        Book book = mapper.readValue(input, Book.class);
        System.out.println(book);

    }
}
